package com.intct.redis;

import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.params.SetParams;

import java.util.HashMap;
import java.util.Map;

/**
 * @author gufg
 * @since 2025-07-18 11:16
 */
public class JedisPoolConnection {
    public static void main(String[] args) {
        // JedisPool配置信息
        GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
        poolConfig.setMaxTotal(1000);
        poolConfig.setMaxIdle(100);
        poolConfig.setMinIdle(10);
        // 创建 JedisPool
        JedisPool jedisPool = new JedisPool(poolConfig, "cdh-node", 6379, "default", "123456");

        // 获取连接池中空闲连接
        Jedis jedis = jedisPool.getResource();

        // 执行Redis命令 hash : hset key field value [field value...]
        Map<String, String> hashMap = new HashMap<>();
        hashMap.put("f1", "v1");
        hashMap.put("f2", "v2");
        hashMap.put("f3", "v3");
        jedis.hset("hash_api", hashMap);

        // 关闭Redis连接
        jedis.close();
    }
}
